package jmu.cultural_tourism.service.impl;

import jmu.cultural_tourism.entity.PostTagInfo;
import jmu.cultural_tourism.dao.PostTagInfoDao;
import jmu.cultural_tourism.service.PostTagInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import jakarta.annotation.Resource;

/**
 * 帖子所包含哪些标签(PostTagInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-07-17 15:33:44
 */
@Service("postTagInfoService")
public class PostTagInfoServiceImpl implements PostTagInfoService {
    @Autowired
    private PostTagInfoDao postTagInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param postTagId 主键
     * @return 实例对象
     */
    @Override
    public PostTagInfo queryById(Integer postTagId) {
        return this.postTagInfoDao.queryById(postTagId);
    }

    /**
     * 分页查询
     *
     * @param postTagInfo 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PostTagInfo> queryByPage(PostTagInfo postTagInfo, PageRequest pageRequest) {
        long total = this.postTagInfoDao.count(postTagInfo);
        return new PageImpl<>(this.postTagInfoDao.queryAllByLimit(postTagInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param postTagInfo 实例对象
     * @return 实例对象
     */
    @Override
    public PostTagInfo insert(PostTagInfo postTagInfo) {
        this.postTagInfoDao.insert(postTagInfo);
        return postTagInfo;
    }

    /**
     * 修改数据
     *
     * @param postTagInfo 实例对象
     * @return 实例对象
     */
    @Override
    public PostTagInfo update(PostTagInfo postTagInfo) {
        this.postTagInfoDao.update(postTagInfo);
        return this.queryById(postTagInfo.getPostTagId());
    }

    /**
     * 通过主键删除数据
     *
     * @param postTagId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer postTagId) {
        return this.postTagInfoDao.deleteById(postTagId) > 0;
    }
}
